// JavaScript Document
$(document).ready(init);

function init(){
	var tab=new idTabs("#idTabs","menuon");
	tab.init();
	
	addListener();
}
function addListener(){
	$("#present ul li").click(changeStyle);	
}
function changeStyle(){
	$(this).siblings(".onli").removeClass("onli");
	$(this).addClass("onli");
	$("#greetings").val(this.title);
}
function loadContext(url,hash){
	var ctrl =null
	try{
		ctrl=getBusyOverlay($("body").get(0));
	}catch(err){
		//alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
	}
	$(hash).load(url,function(){
									if(ctrl!=null) {ctrl.remove();}
									$("#present ul li").click(changeStyle);
							});	
}
function getLove(target){
	loadContext("/tools/ajax.aspx?type=prelist&tid=3",target.hash);
}
function getOther(target){
    loadContext("/tools/ajax.aspx?type=prelist&tid=4", target.hash);
}
function getBirthday(target){
    loadContext("/tools/ajax.aspx?type=prelist&tid=2", target.hash);
}

function sendPresent(target) {
    if ($("#present .onli:visible").length == 0) {
        msgBox("请选择礼物！");
        return;
    }
    var presentID = $("#present .onli:visible").get(0).id;

    var greetings = $("#greetings").val();
    if (greetings == "") {
        msgBox("祝福语不能为空");
        return;
    }

    var userID = $("#userList option:selected").val();
    if (parseInt(userID) == 0) {
        msgBox("还没有好友，不能发送");
        return;
    }

    var ctrl = null
    try {
        ctrl = getBusyOverlay($("body").get(0));
    } catch (err) {
        //alert("\u6D4F\u89C8\u5668\u8FD8\u517C\u5BB9\uFF0C\u90E8\u5206\u6548\u679C\u65E0\u6CD5\u6B63\u5E38\u663E\u793A\uFF01");
    }
    var _url = encodeURI("/tools/ajax.aspx?type=addpresent&presentID=" + presentID + "&greetings=" + greetings + "&userID=" + userID);
    $.ajax({ url: _url,cache:false,
        success: function(data) {
            if (ctrl != null) { ctrl.remove(); }
            if (data == "ok") {
                msgBox("发送成功！");
            }
            else {
                if (data == "nopre") {
                    msgBox("礼物不存在！");
                }
                else {
                    if (data == "nopoint") {
                        msgBox("积分不足！");
                    }
                    else {
                        msgBox("发送失败！");
                    }
                }

            }
        }
    });
}
function changeGroup(target) {
    var groupID = $(target).find("option:selected").val();
    loadContext("/tools/ajax.aspx?type=friendlist&groupID=" + groupID + "&dqid=" + document.getElementById("dquserid").value, "#userList");
}
